import api from './index'
import type {
  ILoginRequest,
  IRegisterRequest,
  IAuthResponse,
  IUserResponse,
  IApiResponse
} from '@/types'

// 用户登录
export const login = (data: ILoginRequest): Promise<IAuthResponse> => {
  return api.post('/auth/login', data)
}

// 用户注册
export const register = (data: IRegisterRequest): Promise<IAuthResponse> => {
  return api.post('/auth/register', data)
}

// 获取当前用户信息
export const getCurrentUser = (): Promise<IApiResponse<IUserResponse>> => {
  return api.get('/auth/me')
}

// 用户登出
export const logout = (): Promise<IApiResponse> => {
  return api.post('/auth/logout')
}

// 导出类型以便其他文件使用
export type { IUserResponse as User }
